package com.hmall.api.interceptor;

import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.index.qual.SameLen;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //远程调用时，服务提供者 如何获取登录用户id?
        //fegiin远程调用时，
        Long loginUserId = UserContext.getUser();
        //也把登录用户id存入请求头
        requestTemplate.header("user-info", String.valueOf(loginUserId));
    }
}
